#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include "../utility/defs.h"
#include "../utility/Gets.h"
#include "../utility/geometry.h"
#include "../shaderMgr.h"
#include "../textureMgr.h"
#include <vector>
#include <string>
using namespace std;

const float GrassWidth = 120.0f;
const float GrassHeight = 120.0f;

const string alpha = "_Alpha";

class cGrass
{
public:
	cGrass(){  }
	void OnInit(string fxname,string texname);
	void Update(float dt);
	void Render();
	void Release();
	void SetGrassGrid(DWORD dwNum,vector<D3DXVECTOR3>& vecGrassPos,float radius,
		float grasswidth = GrassWidth,float grassheight = GrassHeight);
	void SetTexture(string tex);
private:
	float m_GrassHeight,m_GrassWidth;
	D3DXVECTOR3 m_Center;
	float m_Length,m_Width;
	
	ID3DXMesh* m_pMesh;
	ID3DXEffect* m_pEffect;
	LPDIRECT3DDEVICE9 m_pDevice9;
	LPDIRECT3DTEXTURE9 m_pTex;
	LPDIRECT3DTEXTURE9 m_pTexAlpha;
};


//geometry for grass
const int NumGrassVertex = 12;

const D3DXVECTOR3 GrassBias[]={
	D3DXVECTOR3(0.0f,0.0f,-1.0f),//0
	D3DXVECTOR3(-RootThree*0.5,0.0f,0.5f),//pi/3
	D3DXVECTOR3(RootThree*0.5,0.0f,0.5f),//2*pi/3
};

void CreateGrassGeometry(LPDIRECT3DDEVICE9 pDevice9,vector<D3DXVECTOR3>& vecPos,DWORD dwNum,
	float inGrassHeight,float inGrassWidth,float inRadius,ID3DXMesh** outMesh);
void CreatePlaneGrass(LPDIRECT3DDEVICE9 pDevice9,vector<D3DXVECTOR3>& vecGrassPos,DWORD dwNum,
	float inGrassHeight,float inGrassWidth,ID3DXMesh** outMesh);